package com.tjnu.baiyi.interceptor;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.tjnu.baiyi.entity.TbUser;

public class LoginInteceptor extends AbstractInterceptor {
	private static final long serialVersionUID = 7435579369832571982L;

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		// TODO Auto-generated method stub
		HttpSession session = ServletActionContext.getRequest().getSession();
		TbUser user1 = (TbUser) session.getAttribute("currentUser");// 获取当前登录的用户信息
		if (user1 != null) {// 用户存在，即用户已经登录
			return arg0.invoke();// 调用执行方法
		}
		return "login";// 用户尚未登陆，返回登录界面
	}

}
